package com.ruoyi.system.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.system.domain.DzGongdan;
import com.ruoyi.system.service.IDzGongdanService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 工单办理Controller
 * 
 * @author ruoyi
 * @date 2025-04-07
 */
@Controller
@RequestMapping("/system/gongdan")
public class DzGongdanController extends BaseController
{
    private String prefix = "system/gongdan";

    @Autowired
    private IDzGongdanService dzGongdanService;

    @RequiresPermissions("system:gongdan:view")
    @GetMapping()
    public String gongdan()
    {
        return prefix + "/gongdan";
    }

    /**
     * 查询工单办理列表
     */
    @RequiresPermissions("system:gongdan:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(DzGongdan dzGongdan)
    {
        startPage();
        List<DzGongdan> list = dzGongdanService.selectDzGongdanList(dzGongdan);
        return getDataTable(list);
    }

    /**
     * 导出工单办理列表
     */
    @RequiresPermissions("system:gongdan:export")
    @Log(title = "工单办理", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(DzGongdan dzGongdan)
    {
        List<DzGongdan> list = dzGongdanService.selectDzGongdanList(dzGongdan);
        ExcelUtil<DzGongdan> util = new ExcelUtil<DzGongdan>(DzGongdan.class);
        return util.exportExcel(list, "工单办理数据");
    }

    /**
     * 新增工单办理
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存工单办理
     */
    @RequiresPermissions("system:gongdan:add")
    @Log(title = "工单办理", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(DzGongdan dzGongdan)
    {
        return toAjax(dzGongdanService.insertDzGongdan(dzGongdan));
    }

    /**
     * 修改工单办理
     */
    @RequiresPermissions("system:gongdan:edit")
    @GetMapping("/edit/{dezhouGdid}")
    public String edit(@PathVariable("dezhouGdid") Long dezhouGdid, ModelMap mmap)
    {
        DzGongdan dzGongdan = dzGongdanService.selectDzGongdanByDezhouGdid(dezhouGdid);
        mmap.put("dzGongdan", dzGongdan);
        return prefix + "/edit";
    }

    /**
     * 修改保存工单办理
     */
    @RequiresPermissions("system:gongdan:edit")
    @Log(title = "工单办理", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(DzGongdan dzGongdan)
    {
        return toAjax(dzGongdanService.updateDzGongdan(dzGongdan));
    }

    /**
     * 删除工单办理
     */
    @RequiresPermissions("system:gongdan:remove")
    @Log(title = "工单办理", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(dzGongdanService.deleteDzGongdanByDezhouGdids(ids));
    }
}
